package com.example.rentalclearing.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@TableName("rental_payment_schedule")
@Schema(description = "租金支付计划")
public class RentalPaymentSchedule implements Serializable {

    @TableId(type = IdType.AUTO)
    @Schema(description = "主键ID")
    private Long id;

    @Schema(description = "承租人名称（默认关联付款账户名称）")
    private String tenantName;

    @Schema(description = "应收日期")
    private LocalDate receivableDate;

    @Schema(description = "应收总金额")
    private BigDecimal totalReceivableAmount;

    @Schema(description = "应收本金")
    private BigDecimal principalReceivable;

    @Schema(description = "应收利息")
    private BigDecimal interestReceivable;

    @Schema(description = "实收本金")
    private BigDecimal principalReceived = BigDecimal.ZERO;

    @Schema(description = "实收利息")
    private BigDecimal interestReceived = BigDecimal.ZERO;

    @Schema(description = "核销状态：未核销(unwritten)，部分核销(partially_written)，已核销(fully_written)")
    private String writeOffStatus; // unwritten, partially_written, fully_written

    @TableField(fill = FieldFill.INSERT)
    @Schema(description = "创建时间")
    private LocalDateTime createdAt;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Schema(description = "最后更新时间")
    private LocalDateTime updatedAt;

    /**
     * 未收的利息
     */
    public BigDecimal getInterestUnreceived() {
        return this.interestReceivable.subtract(this.interestReceived);
    }

    /**
     * 未收的本金
     */
    public BigDecimal getPrincipalUnreceived() {
        return this.principalReceivable.subtract(this.principalReceived);
    }
}
